package com.zucc.controller;

import com.zucc.controller.req.TopicAddReq;
import com.zucc.controller.req.TopicModifyReq;
import com.zucc.controller.req.TopicSearchReq;
import com.zucc.controller.resp.TopicResp;
import com.zucc.service.TopicService;
import com.zucc.service.base.PageData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author : charspan
 * @Description :
 * @create : 2021-12-11 4:44 下午
 */
@RestController
@Slf4j
@RequestMapping("/v1/api/topics")
@Api(tags = "新闻栏目管理")
public class TopicController {
    @Resource
    private TopicService topicService;

    @ApiOperation(value = "新增栏目")
    @PostMapping
    void add(@RequestBody @Validated TopicAddReq req) {
        topicService.add(req);
    }

    @ApiOperation(value = "修改栏目")
    @PutMapping
    void modify(@RequestBody @Validated TopicModifyReq req) {
        topicService.modify(req);
    }

    @ApiOperation(value = "删除栏目")
    @ApiImplicitParam(paramType = "path", name = "id", value = "栏目编号", dataType = "Long", example = "1", required = true)
    @DeleteMapping("/{id}")
    void deleteOne(@PathVariable Long id) {
        topicService.deleteOne(id);
    }

    @ApiOperation(value = "栏目分页")
    @PostMapping("/page")
    PageData<TopicResp> page(@RequestBody @Validated TopicSearchReq req) {
        return topicService.page(req);
    }
}
